{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "d29569a8",
   "metadata": {},
   "source": [
    "## 本月学习目标（9.06-10.06）\n",
    "### 1. 课本代码(项目一，从奇数中选择对应的时间节点)\n",
    "### 2. 认识变量\n",
    "### 3. if else\n",
    "### 4. for + range"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e2ec50fd",
   "metadata": {},
   "source": [
    "### 一、奇数对应的时间节点"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "d025457a",
   "metadata": {},
   "outputs": [],
   "source": [
    "# 从python基础库（标准库中）找到 datetime模块\n",
    "from datetime import datetime"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "7eb23b48",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "datetime.datetime(2021, 9, 13, 10, 59, 21, 143237)"
      ]
     },
     "execution_count": 2,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "datetime.today()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "6c04290a",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "# 课本代码（项目一，从奇数中选择对应的时间节点）\n",
    "from datetime import datetime\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "right_this_minute = datetime.today().minute\n",
    "\n",
    "if right_this_minute in odds: # 冒号引入缩进的代码组\n",
    "    print(\"This minute seems a little odd.\")\n",
    "    \n",
    "else: # 冒号引入缩进的代码组\n",
    "    print(\"Not an odd minute.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "514bd613",
   "metadata": {},
   "source": [
    "### 二、认识变量\n",
    "1. **变量** 用于存储要在计算机程序中引用和操作的信息。\n",
    "\n",
    "#### 声明变量\n",
    "```\n",
    "1 #_*_coding:utf-8_*_\n",
    "2 \n",
    "3 name =\"Ziyin\"\n",
    "```\n",
    "上述代码声明了一个变量，变量名为： name，变量name的值为：\"Ziyin\"\n",
    "\n",
    "#### 变量的命名规则\n",
    "   * 变量名只能是 字母、数字或下划线的任意组合\n",
    "   * 变量名的第一个字符不能是数字\n",
    "   * 以下关键字不能声明为变量名\n",
    "['and', 'as', 'assert', 'break', 'class', 'continue', 'def', 'del', 'elif', 'else', 'except', 'exec', 'finally', 'for', 'from', 'global', 'if', 'import', 'in', 'is', 'lambda','not', 'or', 'pass', 'print', 'raise', 'return', 'try', 'while', 'with', 'yield']\n",
    "\n",
    "#### 变量的赋值\n",
    "```\n",
    "name = \"Ziyin\"\n",
    "\n",
    "name2 = name\n",
    "print(name,name2)\n",
    "\n",
    "name = \"Juicy\"\n",
    "\n",
    "print(\"What is the value of name2 now?\")\n",
    "```"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "941bdc8f",
   "metadata": {},
   "source": [
    "### 变量（数字，字符串，对象）\n",
    "#### 1、 数字"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "a2415a0a",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "4"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "2+2 "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "28009154",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5.0"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "(50-5*6)/4"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "d0987c8b",
   "metadata": {},
   "source": [
    "#### Ps: type函数—Python中的数据类型（整型、浮点型和 复数 ） \n",
    "```\n",
    ">>>a = 2018\n",
    "\n",
    ">>>type(a)\n",
    "\n",
    "  <class'int'>\n",
    "\n",
    ">>>py_version = 3.7 \n",
    "\n",
    ">>>type(py_version)\n",
    "\n",
    "  <class'float'>\n",
    "\n",
    ">>>b = 3+0.2j\n",
    "\n",
    ">>>type(b)\n",
    "\n",
    "  <class'complex'>\n",
    "```\n",
    "#### 变量会取所赋的那个值的类型。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a528ebbc",
   "metadata": {},
   "source": [
    "#### 2、字符串"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "b4347046",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'eggs'"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'eggs'"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "9040cab5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"dosen't\""
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "\"dosen't\""
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "323560a4",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "\"doesn't\""
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "'doesn\\'t' # 注：这里的 \\ 是转义字符，避免三个’重复"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57ea716f",
   "metadata": {},
   "source": [
    "#### 3、对象\n",
    "#### python中“一切皆是对象”，而且所有对象都可以赋给变量。P48-49 了解"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "fa4701c2",
   "metadata": {},
   "source": [
    "### 三、if else\n",
    "#### if （条件一）满足：\n",
    "#### 则print（某结果）\n",
    "#### elif （条件二）满足：\n",
    "#### 则print（某结果）\n",
    "...\n",
    "#### else：（否则）\n",
    "#### print（此结果）\n",
    "##### 可以进行嵌套。 不要超过3层， 最多5层"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "541f0608",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "study,study,study.\n"
     ]
    }
   ],
   "source": [
    "# if elif else 的运用\n",
    "import time\n",
    "\n",
    "today = time.strftime(\"%A\")\n",
    "\n",
    "if today == 'Saturday':  #if-语句块\n",
    "    print('party!!')\n",
    "elif today == 'Sunday':  #elif-语句块\n",
    "    print('recover.')\n",
    "else:                    #else-语句块\n",
    "    print('study,study,study.')\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "cfa0a783",
   "metadata": {},
   "source": [
    "#### ps：当前时间表达示例"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "e0a709fd",
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/plain": [
       "'10:59'"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import time\n",
    "\n",
    "time.strftime(\"%H:%M\", time.localtime()) #当前时区"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1c094ae7",
   "metadata": {},
   "source": [
    "#### Python课的简易课表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "c240d3e7",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You can teach yourself the techniques of python.\n"
     ]
    }
   ],
   "source": [
    "# python课‘if else’的示例\n",
    "import time\n",
    "\n",
    "today = time.strftime(\"%A\")\n",
    "\n",
    "now = time.strftime(\"%H:%M\", time.localtime())\n",
    "\n",
    "if today == 'Monday':\n",
    "    if now == \"09:45\" < now < \"12:00\":\n",
    "        print(\"It's time to have a python class!\")\n",
    "else:\n",
    "    print(\"You can teach yourself the techniques of python.\")\n",
    "           "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "8bb16278",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "You can teach yourself the techniques of python.\n"
     ]
    }
   ],
   "source": [
    "# Pytho课提前15分钟提醒\n",
    "import time\n",
    "\n",
    "today = time.strftime(\"%A\")\n",
    "\n",
    "now = time.strftime(\"%H:%M\", time.localtime()) \n",
    "\n",
    "if today == 'Monday':\n",
    "    if now == \"09:30:00\" < now < \"9:45:00\":\n",
    "        print(\"Hurry up! You have fifteen minute to prepare python class. Please don't forget it.\")\n",
    "elif now == \"09:45:00\" < now < \"12:00:00\":\n",
    "    print(\"It's time to have a python class!\")\n",
    "else:\n",
    "    print(\"You can teach yourself the techniques of python.\")"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "518398be",
   "metadata": {},
   "source": [
    "### 四、for循环 + 内置函数range（）\n",
    "#### 1、for循环：迭代处理一个对象序列——循环次数已知时使用“for”。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "312e4860",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "1\n",
      "2\n",
      "3\n"
     ]
    }
   ],
   "source": [
    "# 用for循环取一个数字列表，迭代处理列表中的每一个数字，在屏幕上显示当前数字\n",
    "for i in [1,2,3]:\n",
    "    print(i)\n",
    "\n",
    "# 要注意缩进和冒号。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "bfbd19ce",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "H\n",
      "i\n",
      "!\n"
     ]
    }
   ],
   "source": [
    "# 使用for循环迭代处理一个字符串\n",
    "for ch in \"Hi!\":\n",
    "    print(ch)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f105c49c",
   "metadata": {},
   "source": [
    "#### 2、内置函数range() ：迭代指定的次数——range其实决定了for循环执行的次数。"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "3519b388",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n",
      "Head First Rocks!\n"
     ]
    }
   ],
   "source": [
    "# 用range生成一个数字列表，一次向num变量赋一个数\n",
    "for num in range(5):\n",
    "    print('Head First Rocks!')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6cba7ff",
   "metadata": {},
   "source": [
    "#### 课本代码：Range试验"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "39676355",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "range(0, 5)"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "range(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "782a3480",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 1, 2, 3, 4]"
      ]
     },
     "execution_count": 5,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7cec0018",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[5, 6, 7, 8, 9]"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(5,10))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "7d32a1c5",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[0, 2, 4, 6, 8]"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(0,10,2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "id": "6d729349",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[10, 8, 6, 4, 2]"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,-2))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "f5477652",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[]"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(10,0,2))\n",
    "# 若开始值大于结束值，并且步长为正值，只会得到一个空列表"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "bd66b235",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "[99, 89, 79, 69, 59, 49, 39, 29, 19, 9]"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "list(range(99,0,-10))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "6333183e",
   "metadata": {},
   "source": [
    "### Ps: sleep函数——执行暂停的秒数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a81e3891",
   "metadata": {},
   "outputs": [],
   "source": [
    "import time\n",
    "time.sleep(5)\n",
    "# shell暂停5秒，5秒后提示符才会出现\n",
    "# 可以从一个模块导入一个特定的函数。例如，from time import sleep会导入sleep函数，这样无需限定就可以直接调用这个函数。\n",
    "# 如果只是导入一个模块（例如import time），就需要用模块名对这个模块中函数的使用加以限定，如time.sleep() "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "548f85d8",
   "metadata": {},
   "source": [
    "### Ps: random模块中的randint()函数——生成指定范围内的一个随机整数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "1b5fd568",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['BPF',\n",
       " 'LOG4',\n",
       " 'NV_MAGICCONST',\n",
       " 'RECIP_BPF',\n",
       " 'Random',\n",
       " 'SG_MAGICCONST',\n",
       " 'SystemRandom',\n",
       " 'TWOPI',\n",
       " '_Sequence',\n",
       " '_Set',\n",
       " '__all__',\n",
       " '__builtins__',\n",
       " '__cached__',\n",
       " '__doc__',\n",
       " '__file__',\n",
       " '__loader__',\n",
       " '__name__',\n",
       " '__package__',\n",
       " '__spec__',\n",
       " '_accumulate',\n",
       " '_acos',\n",
       " '_bisect',\n",
       " '_ceil',\n",
       " '_cos',\n",
       " '_e',\n",
       " '_exp',\n",
       " '_inst',\n",
       " '_log',\n",
       " '_os',\n",
       " '_pi',\n",
       " '_random',\n",
       " '_repeat',\n",
       " '_sha512',\n",
       " '_sin',\n",
       " '_sqrt',\n",
       " '_test',\n",
       " '_test_generator',\n",
       " '_urandom',\n",
       " '_warn',\n",
       " 'betavariate',\n",
       " 'choice',\n",
       " 'choices',\n",
       " 'expovariate',\n",
       " 'gammavariate',\n",
       " 'gauss',\n",
       " 'getrandbits',\n",
       " 'getstate',\n",
       " 'lognormvariate',\n",
       " 'normalvariate',\n",
       " 'paretovariate',\n",
       " 'randint',\n",
       " 'random',\n",
       " 'randrange',\n",
       " 'sample',\n",
       " 'seed',\n",
       " 'setstate',\n",
       " 'shuffle',\n",
       " 'triangular',\n",
       " 'uniform',\n",
       " 'vonmisesvariate',\n",
       " 'weibullvariate']"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "import random\n",
    "dir(random) # 使用“dir”查询一个对象"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "35dc9ecb",
   "metadata": {},
   "source": [
    "#### 使用“help”读取Python文档——要对randint有更对了解，可以寻求shell的帮助"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "fe60c25e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on method randint in module random:\n",
      "\n",
      "randint(a, b) method of random.Random instance\n",
      "    Return random integer in range [a, b], including both end points.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(random.randint)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "5d46196b",
   "metadata": {},
   "source": [
    "#### 课本试验：randint函数实际使用"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "a9a053f7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "9"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,60)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "58586192",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "1"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(0,3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "bc71b407",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "2"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "random.randint(1,2)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "19796c7c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Not an odd minute.\n",
      "This minute seems a little odd.\n",
      "This minute seems a little odd.\n",
      "Not an odd minute.\n",
      "This minute seems a little odd.\n"
     ]
    }
   ],
   "source": [
    "# 课本代码：项目二，实现for循环和等待的时间\n",
    "from datetime import datetime\n",
    "\n",
    "import random\n",
    "import time\n",
    "\n",
    "odds = [1,3,5,7,9,11,13,15,17,19,21,23,25,27,29,31,33,35,37,39,41,43,45,47,49,51,53,55,57,59]\n",
    "\n",
    "for i in range(5):  # 由于range的存在，将执行5次。\n",
    "    right_this_minute = datetime.today().minute\n",
    "    if right_this_minute in odds:\n",
    "        print(\"This minute seems a little odd.\")\n",
    "    else:\n",
    "        print(\"Not an odd minute.\")\n",
    "    wait_time = random.randint(1,60)  # 增加等待时间\n",
    "    time.sleep(wait_time)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "b3cda45c",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "5 bottles of beer on the wall.\n",
      "5 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "4 bottles of beer on the wall.\n",
      "\n",
      "4 bottles of beer on the wall.\n",
      "4 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "3 bottles of beer on the wall.\n",
      "\n",
      "3 bottles of beer on the wall.\n",
      "3 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "2 bottles of beer on the wall.\n",
      "\n",
      "2 bottles of beer on the wall.\n",
      "2 bottles of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "1 bottle of beer on the wall.\n",
      "\n",
      "1 bottle of beer on the wall.\n",
      "1 bottle of beer.\n",
      "Take one down.\n",
      "Pass it around.\n",
      "No more bottles of beer on the wall.\n",
      "\n"
     ]
    }
   ],
   "source": [
    "# 项目三，啤酒歌谣\n",
    "word = \"bottles\"\n",
    "for beer_num in range(5,0,-1):\n",
    "    print(beer_num, word, \"of beer on the wall.\")\n",
    "    print(beer_num, word, \"of beer.\")\n",
    "    print(\"Take one down.\")\n",
    "    print(\"Pass it around.\")\n",
    "    if beer_num == 1:\n",
    "        print(\"No more bottles of beer on the wall.\")\n",
    "    else:\n",
    "        new_num = beer_num - 1\n",
    "        if new_num == 1:\n",
    "            word = \"bottle\"\n",
    "        print(new_num, word, \"of beer on the wall.\")\n",
    "    print()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "0adeff1e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "9 瓶 1664桃红 在啤酒柜上\n",
      "9 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "8 瓶 1664桃红 在啤酒柜上\n",
      "8 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "7 瓶 1664桃红 在啤酒柜上\n",
      "7 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "6 瓶 1664桃红 在啤酒柜上\n",
      "6 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "5 瓶 1664桃红 在啤酒柜上\n",
      "5 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "4 瓶 1664桃红 在啤酒柜上\n",
      "4 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "3 瓶 1664桃红 在啤酒柜上\n",
      "3 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "\n",
      "2 瓶 1664桃红 在啤酒柜上\n",
      "2 1664桃红 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "2 瓶 1664白啤 在啤酒柜上\n",
      "\n",
      "1 瓶 1664白啤 在啤酒柜上\n",
      "1 1664白啤 :瓶\n",
      "Take one down\n",
      "Pass it aroung\n",
      "没有更多的1664桃红啤酒了\n"
     ]
    }
   ],
   "source": [
    "# 进一步完善的beer song\n",
    "word = \"1664桃红\"\n",
    "for beer_num in range(9,0,-1):\n",
    "    # 调酒师\n",
    "    print(beer_num,\"瓶\",word,\"在啤酒柜上\")\n",
    "    print(beer_num,word,\":瓶\")\n",
    "    print(\"Take one down\")\n",
    "    print(\"Pass it aroung\")\n",
    "    # 客户\n",
    "    if beer_num == 1:\n",
    "        print(\"没有更多的1664桃红啤酒了\")\n",
    "    else:\n",
    "        # 因为数值是可以运算的\n",
    "        new_num = beer_num -1\n",
    "        if new_num == 1:\n",
    "            word = \"1664白啤\"\n",
    "            print(beer_num,\"瓶\",word,\"在啤酒柜上\")\n",
    "        print()"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
